var fs = require("fs");
var _ = require("lodash");

let fileName1 = "ItemDes";
let fileName2 = "TradeGroup";
let outputFileName = "./data/trade.json";

let data1 = JSON.parse(fs.readFileSync(`${fileName1}.json`).toString()).map;
let data2 = JSON.parse(fs.readFileSync(`${fileName2}.json`).toString()).map;

let map1 = new Map();
_.forEach(data1, (e) => {
  let id = e.id;
  let data = e.data;
  map1.set(id, data);
});
_.forEach(data2, (e) => {
  e.data.tradeList = _.map(e.data.tradeList, (x) => {
    if (map1.has(x)) {
      x = map1.get(x);
    }
    return x;
  });
});

fs.writeFileSync(outputFileName, JSON.stringify(data2));
